package test;

public class GMain {
	public static void main(String[] args) {
		GMain app = new GMain();
		int[] res = app.getMins(new int[] {-7,0,1,2,3,4,4,5});
		for(int i = 0; i < res.length; i++) {
			System.out.println(res[i]);
		}
	}
	
	public int[] getMins(int[] a) {
		int ind1 = 0;
		int ind2 = a.length - 1;
		int nextInd = a.length - 1;
		int[] res = new int[a.length];
		while(ind1 <= ind2) {
		  if(-a[ind1] > a[ind2]) {
		    res[nextInd--] = a[ind1] * a[ind1];
		    ind1++;
		  } else {
		    res[nextInd--] = a[ind2] * a[ind2];
		    ind2--;
		  }
		}
		
		return res;
	}
}
